package cn.itcast.users.controller.user;

import cn.itcast.context.BaseContext;
import cn.itcast.result.Result;
import cn.itcast.users.dto.UserLoginDTO;
import cn.itcast.users.pojo.User;
import cn.itcast.users.service.UserService;
import cn.itcast.users.vo.UserLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/user")
@Api(tags = "C端用户相关接口")
@Slf4j
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 用户端微信登录
     * @param userLoginDTO
     * @return
     */
    @PostMapping("/login")
    @ApiOperation("用户端微信登录")
    public Result<UserLoginVO> login(@RequestBody UserLoginDTO userLoginDTO) {
        log.info("用户端微信登录：{}", userLoginDTO);
        UserLoginVO userLoginVO = userService.wxLogin(userLoginDTO);
        return Result.success(userLoginVO);
    }


    /**
     * 用户退出
     * @return
     */
    @PostMapping("/logout")
    @ApiOperation("用户退出")
    public Result<String> logout() {
        log.info("用户退出");
        BaseContext.removeCurrentId();
        return Result.success();
    }


    /**
     * 根据id查询用户信息
     * @param id
     * @return
     */
    @GetMapping("/getById/{id}")
    public User getById(@PathVariable Long id) {
        return userService.getById(id);
    }

}